//
//  WZAboutController.m
//  ETong
//
//  Created by wanzhao on 15/10/30.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZAboutController.h"
#import "WZComInfoFram.h"
#import "WZCompanyInfoCell.h"
#import "WZComInfoFram.h"

@interface WZAboutController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, weak) UIScrollView *scrollView;

@end

@implementation WZAboutController

- (void)dealloc
{
    NSLog(@"WZAboutController dealloc");
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = RGBCOLORWITH16COLOR(0xeeeeee);
    self.navigationItem.title = @"关于我们";
   
    
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.backgroundColor = ClearColor;
    scrollView.hidden = YES;
    scrollView.frame = CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, HARDWARE_SCREEN_HEIGHT - 64);
    [self.view addSubview:scrollView];
    self.scrollView = scrollView;
    
    UIImage *image = [UIImage imageNamed:@"about_us_image"];
    CGFloat imageHeight = (image.size.height / image.size.width) * HARDWARE_SCREEN_WIDTH;
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, imageHeight);
    imageView.image = image;
    [scrollView addSubview:imageView];
    scrollView.contentSize = CGSizeMake(0, imageHeight);
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, HARDWARE_SCREEN_HEIGHT - 64) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = ClearColor;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.scrollEnabled = YES;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.hidden = YES;
    
    [self.view addSubview:self.tableView];

    //创建tablebview的headerview
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = ClearColor;
    headerView.height = 51.0f;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.frame = CGRectMake(OppositeWidthRate(10), 0, self.view.width - OppositeHeightRate(20), OppositeHeightRate(50));
    titleLabel.backgroundColor = ClearColor;
    titleLabel.font = Font18;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    titleLabel.text = @"北京万朝科技有限公司";
    [headerView addSubview:titleLabel];
    
    
    UIView *line1 = [[UIView alloc] init];
    line1.frame = CGRectMake(0, CGRectGetMaxY(titleLabel.frame), self.view.width, OppositeHeightRate(0.5));
    line1.backgroundColor = RGBCOLORWITH16COLOR(0xffffff);
    [headerView addSubview:line1];
    
    
    UIView *line2 = [[UIView alloc] init];
    line2.frame = CGRectMake(0, CGRectGetMaxY(line1.frame), self.view.width, OppositeHeightRate(0.5));
    line2.backgroundColor = RGBCOLORWITH16COLOR(0xd4d4d4);
    [headerView addSubview:line2];
    
    
    self.tableView.tableHeaderView = headerView;
    [self loadData];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
        
}


- (void)loadData
{
    if (self.dataArray.count > 0) {
        self.tableView.hidden = NO;
        self.scrollView.hidden = YES;
    } else {
        self.scrollView.hidden = NO;
        self.tableView.hidden = YES;
    }
}

- (NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WZCompanyInfoCell *infoCell = [WZCompanyInfoCell companyInfoCellWithTableView:tableView];
    
    WZComInfoFram *infoFrame = self.dataArray[indexPath.row];
    infoCell.comInfoFrame = infoFrame;
    
    return infoCell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.1f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    WZComInfoFram *infoFrame = self.dataArray[indexPath.row];
    return infoFrame.cellHeight;
}


@end
